<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <!-- 搜索区域 -->
       <el-input placeholder="请输入内容" style="width: 50%">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!-- 表格区域 -->
      <el-table border stripe :data="orders">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column label="订单价格" prop="order_price"></el-table-column>
        <el-table-column label="是否付款" prop="order_pay">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.order_pay === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="是否发货" prop="is_send"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column width="200" label="操作">
          <template>
            <el-button type="primary" size="mini" @click="editAddress">修改地址</el-button>
            <el-button type="success" size="mini" @click="showExpressProgress">物流进度</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 修改地址 -->
    <el-dialog
      title="修改物流地址" :visible.sync="editAddressDialogVisible" width="50%">
      <el-form ref="form" :model="form">
        <el-form-item label="省市区/县">
        </el-form-item>
        <el-form-item label="详细地址">
         <el-cascader
            v-model="form.cascaderValue"
            :options="cityData"
            :props="cascaderProp"
            @change="handleChange"></el-cascader>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editAddressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editAddressDialogVisible = false">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 物流进度对话框 -->
    <el-dialog title="物流进度" :visible.sync="expressProgressDialogVisible" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(item, index) in expressList"
          :key="index"
          :timestamp="item.time">
          {{item.content}}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from '../../../citydata'
export default {
  data () {
    return {
      // 订单列表查询参数
      queryData: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      orders: [],
      total: 0,
      editAddressDialogVisible: false,
      cityData,
      form: {
        cascaderValue: []
      },
      cascaderProp: {
        expandTrigger: 'hover',
        label: 'label',
        value: 'value',
        children: 'children'
      },
      // 物流进度对话框
      expressProgressDialogVisible: false,
      // 物流进度信息
      expressList: []
    }
  },
  methods: {
    // 获取商品订单列表
    async getOrders () {
      const { data: res } = await this.$axios.get('orders', { params: this.queryData })
      if (res.meta.status !== 200) return this.$message.error('获取订单列表失败！')
      this.orders = res.data.goods
      this.total = res.data.total
    },
    editAddress () {
      this.editAddressDialogVisible = true
    },
    handleChange () {
      console.log(this.form.cascaderValue)
    },
    // 显示物流进度对话框
    async showExpressProgress () {
      this.expressProgressDialogVisible = true
      const { data: res } = await this.$axios.get('http://localhost:8080/api/express')
      console.log(res)
      if (res.meta.status !== 200) return this.$message.error('获取物流信息失败！')
      this.expressList = res.data
    }
  },
  computed: {

  },
  created () {
    this.getOrders()
  }
}
</script>

<style lang='less' scoped>

</style>
